-
Notifications
You must be signed in to change notification settings - Fork 277
Fix/simplify exception handling #3897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/simplify exception handling #3897
Conversation
This makes the code reflect the comment "catch all exceptions here so that this code is not duplicated for each tool".
Using the previous commit these should increase the consistency of how exceptions are handled.
Again, these should only result in a net improvement in how exceptions are handled; return codes shouldn't change.
This does change the exit codes of goto-instrument in the case of exceptions being thrown. Doing so eliminates a long-standing anomoly where goto-instrument had a different exit code for exceptions to all of the other tools.
This changes the return value in a few exceptional cases in favour of being clearer about when an exception is thrown and simplifying the code.
This changes the return value in a few exceptional cases but is more consistent and simpler.
Removes specific handling of a few kinds of exception in favour of the general handlers in parse_options_baset. This will change the exit code in a few exceptional cases but makes the code simpler and more consistent.
01d3ab5
to
5804cb0
Compare
src/util/parse_options.cpp
Outdated
{ | ||
std::cerr << e.what() << '\n'; | ||
return CPROVER_EXIT_EXCEPTION; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this case actually needed? Shouldn't the cprover_exception_baset
below catch all of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so but it was an explicit case in the code I removed so I thought that it had been separated out for a reason and that reason should be preserved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, but then you might add an extra commit that removes it? You've got a catch-all at the very end anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a commit that does this. Please merge if you are happy with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martin-cs Historical note: When it was created there originally wasn't a base class, so we had separate handlers for each exception. A base class was added by vote. Also, we weren't entirely sure if all kinds of exceptions used the same exit code. Both of these situations were eventually remedied, so I don't think it's necessary anymore. This probably slipped past us when the situation changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: 5804cb0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98315938
For ease of migration this case was kept from the calling code. However it is actually redundant and so is removed in this commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo minor comments
src/util/parse_options.cpp
Outdated
{ | ||
std::cerr << e.what() << '\n'; | ||
return CPROVER_EXIT_EXCEPTION; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martin-cs Historical note: When it was created there originally wasn't a base class, so we had separate handlers for each exception. A base class was added by vote. Also, we weren't entirely sure if all kinds of exceptions used the same exit code. Both of these situations were eventually remedied, so I don't think it's necessary anymore. This probably slipped past us when the situation changed.
@@ -40,7 +40,6 @@ Author: Martin Brain, [email protected] | |||
/// An (unanticipated) exception was thrown during computation. | |||
#define CPROVER_EXIT_EXCEPTION 6 | |||
// should contemplate EX_SOFTWARE from sysexits.h | |||
#define CPROVER_EXIT_EXCEPTION_GOTO_INSTRUMENT 11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will lead to a change in exit code for goto-instrument
. That doesn't bother me personally, but it's a change in behaviour, not sure if it needs to documented somewhere. Also, the comment above should be removed together with this #define
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
It is documented in the commit message.
-
The comment is general to all
CPROVER_EXIT_EXCEPTION
, not specifically this one.
if(set_properties()) | ||
return CPROVER_EXIT_SET_PROPERTIES_FAILED; | ||
if(cmdline.isset("property")) | ||
::set_properties(goto_model, cmdline.get_values("property")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this change mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After removing the try
block, set_properties
only contained the two lines I've introduced and then return false
so I inlined them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: 2212653).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98344221
Will this work at all with --json-ui, or --xml-ui? No error reporting for those anymore? |
I think the exception text will be printed to std::err rather than message() but TBH it was a bit of a mish-mash where it would go before this patch. |
That needs to be sorted -- all UI integrations I know rely on these showing up in the JSON. |
(We should have had a test...) |
Error-reporting is important, yet undertested, as shown by #3897.
Error-reporting is important, yet undertested, as shown by #3897.
Error-reporting is important, yet undertested, as shown by #3897.
Error-reporting is important, yet undertested, as shown by #3897.
Error-reporting is important, yet undertested, as shown by #3897.
@kroening : I'll work on a patch to make sure the we always get the exception text to the right output channel. It seems there are two ways of doing this : have |
PR to allow redirection is here : diffblue/gnat2goto#113 |
We had a half implemented good idea in parse_options_baset in which the main method would catch all of the various exceptions and do a standard "print and then exit with the right code" handling so that it didn't need to be duplicated in each binary. The first patch extends this so it really does catch all exceptions, the rest of the patches (ordered in increasing intrusiveness / objectionableness) then remove the redundant (and in many cases inconsistent) exception handling from various main program loops. One thing that isn't done is removing the block parts of the try as it results in large, kinda pointless whitespace commits. I'll do them if people want.